import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:live_music/event/videoListEvent.dart';
import 'package:live_music/models/moment_detail_model.dart';
import 'package:live_music/pages/other/index.dart';
import 'package:live_music/pages/video/video_list.dart';
import 'package:live_music/utils/eventBusUtils.dart';

class VideoAndUserPage extends StatefulWidget {
  VideoAndUserPage({Key key, this.momentListItem}) : super(key: key);
  MomentDetailModel momentListItem;
  @override
  _VideoAndUserPageState createState() => _VideoAndUserPageState();
}

class _VideoAndUserPageState extends State<VideoAndUserPage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  TabController _tabController;
  List<Widget> _tabsContent;
  final List<Widget> _tabs = [Text('关注'), Text('发现')];
  @override
  void initState() {
    super.initState();
    setState(() {
      _tabsContent = [
        VideoListPage(
            momentId: widget.momentListItem != null
                ? widget.momentListItem.id
                : int.parse(Get.parameters['id'])),
        PageViewOtherFromVideoList()
      ];
    });
    _tabController = TabController(
      initialIndex: 0,
      length: _tabs.length,
      vsync: this,
    );
    _tabController.addListener(() {
      if (_tabController.index == 1) {
        EventBusUtils.getInstance().fire(CurVideoToMimeEvent());
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    double screenWidth = MediaQuery.of(context).size.width;
    return Scaffold(
        body: Column(
      children: [
        Container(
            width: 0,
            height: 0,
            child: ExtendedTabBar(
              indicatorSize: TabBarIndicatorSize.label,
              controller: _tabController,
              indicatorColor: Colors.red,
              indicatorWeight: 0,
              unselectedLabelStyle: TextStyle(
                  color: Colors.grey[600], // 下划线颜色
                  fontSize: 14,
                  fontWeight: FontWeight.w600),
              labelStyle: TextStyle(
                  color: Colors.white,
                  fontSize: 15,
                  fontWeight: FontWeight.w700), //标签文字大小颜色
              tabs: _tabs,
            )),
        Container(
            width: screenWidth,
            height: MediaQuery.of(context).size.height,
            child: ExtendedTabBarView(
              controller: _tabController,
              children: _tabsContent,
            ))
      ],
    ));
  }

  @override
  bool get wantKeepAlive => true;
}
